package com.cdtu.stocksage.goods.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cdtu.stocksage.common.annotation.Log;
import com.cdtu.stocksage.common.core.controller.BaseController;
import com.cdtu.stocksage.common.core.domain.AjaxResult;
import com.cdtu.stocksage.common.enums.BusinessType;
import com.cdtu.stocksage.goods.domain.ErsGoodsOutRecord;
import com.cdtu.stocksage.goods.service.IErsGoodsOutRecordService;
import com.cdtu.stocksage.common.utils.poi.ExcelUtil;
import com.cdtu.stocksage.common.core.page.TableDataInfo;

/**
 * 物资出库记录Controller
 * 
 * @author SL
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/goods/outrecord")
public class ErsGoodsOutRecordController extends BaseController
{
    @Autowired
    private IErsGoodsOutRecordService ersGoodsOutRecordService;

    /**
     * 查询物资出库记录列表
     */
    @PreAuthorize("@ss.hasPermi('goods:outrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErsGoodsOutRecord ersGoodsOutRecord)
    {
        startPage();
        List<ErsGoodsOutRecord> list = ersGoodsOutRecordService.selectErsGoodsOutRecordList(ersGoodsOutRecord);
        return getDataTable(list);
    }

    /**
     * 导出物资出库记录列表
     */
    @PreAuthorize("@ss.hasPermi('goods:outrecord:export')")
    @Log(title = "物资出库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErsGoodsOutRecord ersGoodsOutRecord)
    {
        List<ErsGoodsOutRecord> list = ersGoodsOutRecordService.selectErsGoodsOutRecordList(ersGoodsOutRecord);
        ExcelUtil<ErsGoodsOutRecord> util = new ExcelUtil<ErsGoodsOutRecord>(ErsGoodsOutRecord.class);
        util.exportExcel(response, list, "物资出库记录数据");
    }

    /**
     * 获取物资出库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:outrecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(ersGoodsOutRecordService.selectErsGoodsOutRecordById(id));
    }

    /**
     * 新增物资出库记录
     */
    @PreAuthorize("@ss.hasPermi('goods:outrecord:add')")
    @Log(title = "物资出库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErsGoodsOutRecord ersGoodsOutRecord)
    {
        return toAjax(ersGoodsOutRecordService.insertErsGoodsOutRecord(ersGoodsOutRecord));
    }

    /**
     * 修改物资出库记录
     */
    @PreAuthorize("@ss.hasPermi('goods:outrecord:edit')")
    @Log(title = "物资出库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErsGoodsOutRecord ersGoodsOutRecord)
    {
        return toAjax(ersGoodsOutRecordService.updateErsGoodsOutRecord(ersGoodsOutRecord));
    }

    /**
     * 删除物资出库记录
     */
    @PreAuthorize("@ss.hasPermi('goods:outrecord:remove')")
    @Log(title = "物资出库记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ersGoodsOutRecordService.deleteErsGoodsOutRecordByIds(ids));
    }
}
